// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    this.checkLoginStatus();

    // 获取系统信息
    wx.getSystemInfo({
      success: e => {
        this.globalData.systemInfo = e;
        this.globalData.statusBarHeight = e.statusBarHeight;
        this.globalData.windowHeight = e.windowHeight;
        this.globalData.windowWidth = e.windowWidth;
      }
    });
  },
  
  // 检查登录状态
  checkLoginStatus() {
    const token = wx.getStorageSync('token');
    if (!token) {
      console.log('用户未登录');
      this.globalData.isLoggedIn = false;
    } else {
      console.log('用户已登录');
      this.globalData.isLoggedIn = true;
      // 可以在这里做token有效性验证
    }
  },
  
  // 全局数据
  globalData: {
    userInfo: null,
    isLoggedIn: false,
    statusBarHeight: 0,
    windowHeight: 0,
    windowWidth: 0,
    systemInfo: null,
    apiBaseUrl: 'http://localhost:9001'
  }
}) 